﻿using System;
using System.Collections.Generic;
using System.Text;

namespace Atom.NetFrame
{
    /// <summary>
    /// 用户池
    /// </summary>
    public class UserTokenPool
    {
        private Stack<UserToken> pool;

        /// <summary>
        /// 预加载的用户访问类的最大数量
        /// </summary>
        /// <param name="max"></param>
        public UserTokenPool(int max)
        {
            pool = new Stack<UserToken>(max);
        }

        /// <summary>
        /// 从池中拿出一个用户访问类，用来创建链接
        /// </summary>
        /// <returns></returns>
        public UserToken Pop()
        {
            return pool.Pop();
        }
        /// <summary>
        /// 一个用户访问断开链接，回收回用户访问池中
        /// </summary>
        /// <param name="userToken"></param>
        public void Push(UserToken userToken)
        {
            pool.Push(userToken);
        }
    }
}
